{
g_autoptr(GOptionContext) context = NULL;
g_autoptr(OstreeRepo) repo = NULL;
- gboolean ret = FALSE;
const char *op;
const char *section_key;
const char *value;
g_autofree char *section = NULL;
g_autofree char *key = NULL;
- GKeyFile *config = NULL;
+ g_autoptr(GKeyFile) config = NULL;
context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)");
if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
- goto out;
+ return FALSE;
if (argc < 2)
{
ot_util_usage_error (context, "OPERATION must be specified", error);
- goto out;
+ return FALSE;
}
op = argv[1];
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"GROUP name, KEY and VALUE must be specified");
- goto out;
+ return FALSE;
}
section = g_strdup(opt_group);
key = g_strdup(argv[2]);
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"KEY and VALUE must be specified");
- goto out;
+ return FALSE;
}
section_key = argv[2];
value = argv[3];
if(!split_key_string (section_key, §ion, &key, error))
- goto out;
+ return FALSE;
}
config = ostree_repo_copy_config (repo);
g_key_file_set_string (config, section, key, value);
if (!ostree_repo_write_config (repo, config, error))
- goto out;
+ return FALSE;
}
else if (!strcmp (op, "get"))
{
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Group name and key must be specified");
- goto out;
+ return FALSE;
}
section = g_strdup(opt_group);
key = g_strdup(argv[2]);
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"KEY must be specified");
- goto out;
+ return FALSE;
}
section_key = argv[2];
if (!split_key_string (section_key, §ion, &key, error))
- goto out;
+ return FALSE;
}
readonly_config = ostree_repo_get_config (repo);
value = g_key_file_get_string (readonly_config, section, key, error);
if (value == NULL)
- goto out;
+ return FALSE;
g_print ("%s\n", value);
}
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Group name and key must be specified");
- goto out;
+ return FALSE;
}
section = g_strdup(opt_group);
key = g_strdup(argv[2]);
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"KEY must be specified");
- goto out;
+ return FALSE;
}
section_key = argv[2];
if (!split_key_string (section_key, §ion, &key, error))
- goto out;
+ return FALSE;
}
config = ostree_repo_copy_config (repo);
!g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
{
g_propagate_error (error, g_steal_pointer (&local_error));
- goto out;
+ return FALSE;
}
}
if (local_error == NULL && !ostree_repo_write_config (repo, config, error))
- goto out;
+ return FALSE;
}
else
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"Unknown operation %s", op);
- goto out;
+ return FALSE;
}
- ret = TRUE;
- out:
- if (config)
- g_key_file_free (config);
- return ret;
+ return TRUE;
}